//C07:WorldList.cpp
// Display a list of words used in a document.
#include <algorithm>
#include <cctype>
#include <fstream>
#include <iostream>
#include <iterator>
#include <set>
#include <sstream>
#include <string>
#include "../require.h"
using namespace std;

char replaceJunk(char c)
{
    // Only keep alphas, space (as a delimeter), and '
    return (isalpha(c) || c == '\'') ? c : ' ';
}

int main(int argc, char* argv[])
{
    char* fname = "WordList.cpp";
    if(argc > 1)
    {
        fname = argv[1];
    }
    ifstream in(fname);
    assure(in, fname);
    set<string> wordList;
    string line;
    while(getline(in, line))
    {
        transform(line.begin(), line.end(), line.begin(), replaceJunk);
        istringstream is(line);
        string word;
        while(is >> word)
        {
            wordList.insert(word);
        }
    }
    // Output results:
    copy(wordList.begin(), wordList.end(),
        ostream_iterator<string>(cout, "\n"));
}